﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace GraphicsEditor
{
    public class PencilTool : BrushTool
    {
        private Point brushPrev;
        public PencilTool()
        {
            pixelDown = new Point(0, 0);
            pixelUp = new Point(0, 0);
        }
        public override void mouseMoved(Point mouseLoc, PictureBoxAdvance pictureWindow, ImageForm imageform, bool mouseDown)
        {
            if (mouseDown)
            {
                brushPrev = pixelDown;
                Graphics gfx = Graphics.FromImage(pictureWindow.Image);
                SolidBrush brush = new SolidBrush(ToolBox.selectedColor);
                Pen pen = new Pen(brush, 1); // int set to one so pencil is only ever one pixel big

                if (!undoPushed) // if mouse was just clicked to start to draw object; first time through on this mouseDown
                {
                    imageform.undo(); // push image to undo stack (before new object gets drawn on it)

                    undoPushed = true;  // toggle so we know we already pushed to stack so we don't push
                                        // an image everytime we screen redraw (every time dirty is true),
                                        // otherwise stack gets full of the obkect being adjusted by user
                }

                gfx.DrawLine(pen, brushPrev, mouseLoc);
                pictureWindow.Refresh();
                gfx.Dispose();
                pen.Dispose();
                brush.Dispose();
                brushPrev = mouseLoc;
                pixelDown = getPixelPositionUsingMouse(mouseLoc, pictureWindow);
            }
            else // if mouse is unclicked / final object has been drawn
            {
                undoPushed = false; // notes that current image hasnt been pushed onto undo stack yet
            }
        }
    }
}
